package threadpool.demo;

import java.util.concurrent.Semaphore;

/**
 * @author: knowno
 * @create: 2024-09-14 14:22
 * @Version 1.0
 **/
public class SemaThread implements  Runnable{

    //1 创建一个信号量对象
    Semaphore semaphore = new Semaphore(5);

    @Override
    public void run() {

        //2 获取许可
        try {
            semaphore.acquire();

            //延迟
            Thread.sleep(5000);

            //输出
            System.out.println(Thread.currentThread().getName()+" ... 完成输出!");

        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        //3 释放
        semaphore.release();
    }
}
